//
//  WorkflowHistoryListCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 2017/9/13.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "WorkflowHistoryListCell.h"

#define HeadImageSize       45
#define BorderLeftRightMargin        10
#define ControlLeftRightMargin          10
#define ControlTopBottomMargin          10

@interface WorkflowHistoryListCell()
{
    UILabel *_changedTimeLabel;
    UILabel *_activityNameLabel;
    UILabel *_changedUserNameLabel;
    
    UIView *_line1;
    UIView *_line2;
    UIImageView *_circleImageView;
    
    UIView *_backView;
}
@end

@implementation WorkflowHistoryListCell

-(id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    self.backgroundColor = [UIColor colorWithHex:mcrmSAASUISkinColorTextStylef1f4f7Color];
 
    _line1 = [[UIView alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 5 , 0.5)];
    _line1.backgroundColor = [UIColor colorWithHex:0x251A72];
    [self.contentView addSubview:_line1];
    
    _circleImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_green_circle"]];
    _circleImageView.height = 20;
    [self.contentView addSubview:_circleImageView];
    
    _line2 = [[UIView alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 5 , 0.5)];
    _line2.backgroundColor = [UIColor colorWithHex:0x251A72];
    [self.contentView addSubview:_line2];
    
    _backView = [[UIView alloc] initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 0)];
    _backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_backView];
    
    CGSize s = [NSString charSizeWithSystemFontSize:10];
    _changedTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*20, s.height)];
    _changedTimeLabel.font = [UIFont systemFontOfSize:10];
    _changedTimeLabel.textAlignment = NSTextAlignmentLeft;
    [_backView addSubview:_changedTimeLabel];
 
    s = [NSString charSizeWithSystemFontSize:13];
    _activityNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*10, s.height)];
    _activityNameLabel.font = [UIFont systemFontOfSize:13];
    _activityNameLabel.textAlignment = NSTextAlignmentLeft;
    [_backView addSubview:_activityNameLabel];
    
    s = [NSString charSizeWithSystemFontSize:13];
    _changedUserNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*10, s.height)];
    _changedUserNameLabel.font = [UIFont systemFontOfSize:13];
    _changedUserNameLabel.textAlignment = NSTextAlignmentLeft;
    [_backView addSubview:_changedUserNameLabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _line1.height = self.contentView.height/2.0 - _circleImageView.height/2.0 - 5;
    
    _circleImageView.top = _line1.bottom + 5;
    _circleImageView.centerX = _line1.centerX;
    
    _line2.top = _circleImageView.bottom + 5;
    _line2.height = _line1.height;
    
    _backView.top = BorderLeftRightMargin;
    _backView.left = _line1.right + ControlLeftRightMargin;
    _backView.width = self.contentView.width - _line1.right - 2*ControlLeftRightMargin;
    _backView.height = self.contentView.height - 2*ControlLeftRightMargin;
    
    _changedTimeLabel.left = BorderLeftRightMargin;
    _changedTimeLabel.top = BorderLeftRightMargin;
    _changedTimeLabel.width = _backView.width - 2*ControlLeftRightMargin;
    
    _changedUserNameLabel.left = _changedTimeLabel.left;
    _changedUserNameLabel.top = _changedTimeLabel.bottom + ControlTopBottomMargin;
    _changedUserNameLabel.width = _backView.width - 2*ControlLeftRightMargin;
    
    _activityNameLabel.left = _changedTimeLabel.left;
    _activityNameLabel.top = _changedUserNameLabel.bottom + ControlTopBottomMargin;
    _activityNameLabel.width = _backView.width - 2*ControlLeftRightMargin;
}

-(void)setChangedTime:(NSDate *)changedTime
{
    _changedTimeLabel.text = [changedTime toStringDate:yMdHm];
}

-(void)setChangedUserName:(NSString *)changedUserName
{
    _changedUserNameLabel.text = changedUserName;
}

-(void)setActivityName:(NSString *)activityName
{
    _activityNameLabel.text = activityName;
}

+(CGFloat)caleHeight:(CGFloat)containWidth;
{
    CGFloat height = 0 ;
    
    height += BorderLeftRightMargin;
    
    //changedTimeLabel
    height += BorderLeftRightMargin;
    CGSize s = [NSString charSizeWithSystemFontSize:10];
    height += s.height;
    
    //changedUserNameLabel
    height += ControlTopBottomMargin;
    s = [NSString charSizeWithSystemFontSize:13];
    height += s.height;
    
    //activityNameLabel
    height += ControlTopBottomMargin;
    s = [NSString charSizeWithSystemFontSize:13];
    height += s.height;
    height += BorderLeftRightMargin;
    
    height += BorderLeftRightMargin;
    
    return height;
}
@end
